<?php
require_once 'Mobitv/Admin/Action.php';
require_once 'Mobitv/Upload.php';
class UploadAction extends Mobitv_Admin_Action
{
    public function execute()
    {
        $this->checkPermission();
        $this->updateLoginStatus();
        $subcpId = 0;
        $memberId = $_SESSION['userid'];
        $memberName = $_SESSION['username'];
        $adminDao = Vega_Dao::factory('Mobitv_Admin_Admin');
        
        // Check subCP
        $parentId = $adminDao->isSubCp($memberId);
        if($parentId) {
            $subcpId = $memberId;
            $memberId = $parentId;
        }

        // Init upload
        $uploader = new FileUpload();
        $keyname = $uploader->getKeyname();
        $keyvalue = $uploader->generateKey();

        $subCpList = !$subcpId ? $adminDao->getSubCpList($memberId) : array();
        $cats = Vega_Dao::factory('Mobitv_Admin_Videocat')->getList();
        $admin = $adminDao->getAssignmentInfo($memberId);
        $uploadSizeLimit = $admin['upload_size_limit'] ? $admin['upload_size_limit'] : $this->_config['upload']['allowed_size_limit'];
        
        $this->_view->assign('cats', $cats);
        $this->_view->assign('keyname', $keyname);
        $this->_view->assign('keyvalue', $keyvalue);
        $this->_view->assign('memberId', $memberId);
        $this->_view->assign('subcpId', $subcpId);
        $this->_view->assign('subCpList', $subCpList);
        $this->_view->assign('uploadSizeLimit', $uploadSizeLimit);
        $this->_view->assign('uploadFileType', $this->_config['upload']['allowed_file_type']);
        $this->_view->assign('config', $this->_config);
    }
}